<template>
  <a-card :bordered="false">
    <div style="display: flex; justify-content: space-between">
      <!-- 操作按钮区域 -->
      <div class="table-operator">
        <!-- <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('订单表')">导出</a-button>
      <a-upload
        name="file"
        :showUploadList="false"
        :multiple="false"
        :headers="tokenHeader"
        :action="importExcelUrl"
        @change="handleImportExcel"
      >
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload> -->
      </div>
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-form-item label="城市服务商" style="margin-right: 10px" v-has="'xhdjFundLog:select'">
            <serveSelect @selectClick="selectClick" :value="queryParam.agencyCode"></serveSelect>
          </a-form-item>
          <a-form-item label="收支类型" style="margin-right: 10px">
            <a-select v-model="queryParam.billType" style="width: 120px" placeholder="请选择" @change="searchQuery">
              <a-select-option value="1"> 收入 </a-select-option>
              <a-select-option value="2"> 支出 </a-select-option>
            </a-select>
          </a-form-item>
          <a-form-item label="资金流水类型" style="margin-right: 10px">
            <a-select
              v-model="queryParam.type"
              style="width: 120px"
              :options="types"
              placeholder="请选择"
              @change="searchQuery"
            >
            </a-select>
          </a-form-item>
          <a-form-item label="用户类型" style="margin-right: 10px">
            <a-select v-model="queryParam.userType" style="width: 120px" placeholder="请选择" @change="searchQuery">
              <a-select-option value="0"> 普通用户 </a-select-option>
              <a-select-option value="1"> 技师 </a-select-option>
              <a-select-option value="2"> 分销商 </a-select-option>
            </a-select>
          </a-form-item>
          <a-form-item label="来源单号" style="margin-right: 10px">
            <a-input
              placeholder="请输入来源单号"
              v-model="queryParam.sourceOrderNo"
              @pressEnter="searchQuery"
            ></a-input>
          </a-form-item>
          <a-form-item label="用户编号" style="margin-right: 10px">
            <a-input placeholder="请输入用户或者技师" v-model="queryParam.userId" @pressEnter="searchQuery"></a-input>
          </a-form-item>
          <div>
            <a-form-item label="开始时间" style="margin-right: 10px">
              <a-date-picker v-model="queryParam.startTime" :valueFormat="'YYYY-MM-DD'" @change="startChange" />
            </a-form-item>
            <a-form-item label="结束时间" style="margin-right: 10px">
              <a-date-picker
                v-model="queryParam.endTime"
                :valueFormat="'YYYY-MM-DD'"
                @change="endChange"
                :disabled-date="disabledDate"
              />
            </a-form-item>
          </div>
        </a-form>
      </div>
    </div>

    <!-- table区域-begin -->
    <!-- <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div> -->
    <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
    <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      class="j-table-force-nowrap"
      @change="handleTableChange"
    >
      <span slot="action" slot-scope="text, record">
        <a @click="handleEdit(record)">编辑</a>

        <a-divider type="vertical" />
        <a-dropdown>
          <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
          <a-menu slot="overlay">
            <a-menu-item>
              <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                <a>删除</a>
              </a-popconfirm>
            </a-menu-item>
          </a-menu>
        </a-dropdown>
      </span>
    </a-table>

    <!-- table区域-end -->
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import serveSelect from '@/components/serveSelect.vue'

import moment from 'moment'
export default {
  name: 'xhdjFundLog',
  mixins: [JeecgListMixin],
  components: { serveSelect },
  data () {
    return {
      description: '订单表管理页面',
      // 表头pickerOptions: {
      types: [
        { label: '预约下单', value: '0' },
        { label: '返佣', value: '1' },
        { label: '退款', value: '2' },
        { label: '余额充值', value: '3' },
        { label: '技师车费提现', value: '4' },
        { label: '余额充值赠送', value: '5' },
        { label: '技师车费收入', value: '6' },
        { label: '会员卡充值', value: '7' },
        { label: '活动赠送过期', value: '8' },
        { label: '技师服务收入', value: '9' },
        { label: '技师服务收入提现', value: '10' },
        { label: '广告费', value: '31' },
        { label: '系统充值', value: '32' },
        { label: '技师佣金提现', value: '41' },
        { label: '用户佣金提现', value: '50' },
        { label: '物料购买', value: '60' },
        { label: '物料退款', value: '61' },

      ],
      columns: [
        {
          title: '用户编号',
          align: 'center',
          dataIndex: 'userId'
        },
        {
          title: '姓名',
          align: 'center',
          dataIndex: 'name'
        },
        {
          title: '用户类型',
          align: 'center',
          dataIndex: 'userType',
          customRender: (text, record) => {
            return record.userType === 0 ? '用户 ' : '技师'
          }
        },
        {
          title: '收支类型',
          align: 'center',
          dataIndex: 'billType',
          customRender: (text, record) => {
            return record.billType === 1 ? '收入 ' : '支出'
          }
        },
        {
          title: '总金额',
          align: 'center',
          dataIndex: 'totalAmount'
        },
        {
          title: '实际金额',
          align: 'center',
          dataIndex: 'amount'
        },
        {
          title: '操作后的余额',
          align: 'center',
          dataIndex: 'afterAmount'
        },
        {
          title: '操作后的其他余额',
          align: 'center',
          dataIndex: 'afterOtherAmount'
        },
        {
          title: '账单类型',
          align: 'center',
          dataIndex: 'type',
          customRender: (text, record) => {
            let a = this.types.find(res => res.value == record.type)
            return a.label
          }
        },
        {
          title: '来源单号',
          align: 'center',
          dataIndex: 'sourceOrderNo'
        },
        {
          title: '入账时间',
          align: 'center',
          dataIndex: 'createTime'
        }
      ],
      url: {
        list: '/finance/sysxhdjFundsLog/backlist'
      }
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    startChange (value) {
      if (value) {
        this.queryParam.startTime = value + ' 00:00:00'
      } else {
        this.queryParam.startTime = value
      }
    },
    selectClick (value) {
      this.queryParam.agencyCode = value
      this.searchQuery()
    },
    endChange (value) {
      if (value) {
        this.queryParam.endTime = value + ' 23:59:59'
      } else {
        this.queryParam.endTime = value
      }
    },
    disabledDate (time) {
      return new Date(time).getTime() < new Date(this.queryParam.startTime).getTime()
    }
  }
}
</script>
<style lang="less" scoped>
@import '~@assets/less/common.less';
.ant-row {
  display: flex;
  justify-content: flex-end;
}
.ant-col {
  display: flex;
  justify-content: flex-end;
}
.ant-form {
  display: flex;
}
</style>
